import axios from 'axios'
import {Message} from "element-ui";
import message from "element-ui/src/locale/lang/mn";
import router from '../router'


//请求拦截器
axios.interceptors.request.use(config=>{
    //如果存在token请求携带这个token
    if(window.sessionStorage.getItem('tokenStr')){
        config.headers['Authorization']=window.sessionStorage.getItem('tokenStr');
    }
    return config;
},error=>{
    console.log(error);
});



let base= '';


//发送一个json格式的post请求
export const postRequest=(url,params)=>{
    return axios({
        method:'post',
        url: `${base}${url}`,
        data:params
    })
};


//传输 json 的 get 请求
export const getRequest = (url,params)=>{
    return axios({
        method:'get',
        url:`${base}${url}`,
        data:params
    })
};

//传送json的 put请求
export const putRequest=(url,params)=>{
    return axios({
        method:'put',
        url:`${base}${url}`,
        data:params
    })
};

export const deleteRequest=(url,params)=>{
    return axios({
        method:'delete',
        url:`${base}${url}`,
        data:params
    })
};